package com.example.sale.config;

import com.example.sale.Interceptor.JWTInterceptor;
import com.example.sale.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    private final JwtUtil jwtUtil;

    @Autowired
    public InterceptorConfig(JwtUtil jwtUtil) {
        this.jwtUtil = jwtUtil;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTInterceptor(jwtUtil))
                .addPathPatterns("/user/test",
                        "/userDetail/data",
                        "/userDetail/getUserid",
                        "/userDetail/getAll",
                        "/userDetail/id/**",
                        "/userDetail/detailData",
                        "/userDetail/search",
                        "/userDetail/DeleteByIds",
                        "/product/post",
                        "/product/search",
                        "/product/DeleteByIds",
                        "/product/id/**",
                        "/product/putData",
                        "/userDetail/selfData",
                        "/userDetail/detailId",
                        "/userDetail/checkExist",
                        "/userDetail/photo",
                        "productDetail/post",
                        "productDetail/GetBYUserId",
                        "feedback/post",
                        "feedback/search",
                        "feedback/Change",
                        "feedback/id/**",
                        "feedback/selfData",
                        "feedback/selfFeedback",
                        "alipay/notify",
                        "alipay/pay",
                        "user/ChangePassword",
                        "productDetail/") // 拦截的路径
                .excludePathPatterns("/user/login",
                        "/userDetail/checkValid",
                        "/excel/export",
                        "/File/upImg",
                        "/excel/exportProduct",
                        "/captcha",
                "/test/getAll"); // 放行的路径
    }
}